﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace nb.development.csmediamanager
{
    public partial class Resize : Form
    {
        public Resize(int Height, int Width)
        {
            InitializeComponent();
            this.OrHeight = Height;
            this.height.Value = Height;
            this.OrWidth = Width;
            this.width.Value = Width;
            this.heightP.Value = 100;
            this.widthP.Value = 100;
            this.ratioH = ((Height + 0.00) / (Width + 0.00));
            this.ratioW = ((Width + 0.00) / (Height + 0.00));
        }

        private int OrHeight, OrWidth;
        private double ratioH, ratioW;

        public int ImageHeight { get { return Convert.ToInt32(height.Value); } }
        public int ImageWidth { get { return Convert.ToInt32(width.Value); } }

        public event ResizeChangeHandler Resized;

        private void height_ValueChanged(object sender, EventArgs e)
        {
            heightP.Value = Convert.ToInt32(Math.Round((Convert.ToDouble(height.Value) / (OrHeight + 0.00)) * 100, 0));
            if (Resized != null) Resized();
        }

        private void width_ValueChanged(object sender, EventArgs e)
        {
            widthP.Value = Convert.ToInt32(Math.Round((Convert.ToDouble(width.Value) / (OrWidth + 0.00)) * 100, 0));
            if (Resized != null) Resized();
        }

        private void heightP_ValueChanged(object sender, EventArgs e)
        {
            if (locked.Checked)
                widthP.Value = heightP.Value;
            height.Value = Convert.ToInt32(Math.Round(((OrHeight + 0.00) / 100.00) * Convert.ToDouble(heightP.Value), 0));
        }

        private void widthP_ValueChanged(object sender, EventArgs e)
        {
            if (locked.Checked)
                widthP.Value = heightP.Value;
            width.Value = Convert.ToInt32(Math.Round(((OrWidth + 0.00) / 100.00) * Convert.ToDouble(widthP.Value), 0));
        }
    }
    public delegate void ResizeChangeHandler();
}
